package com.JavaWK4_1;

import java.util.HashSet;
import java.util.Objects;

public class work4_1 {
    public static void main(String[] args) {
        HashSet<Person> Hs = new HashSet<Person>();

        Hs.add(new Person("Mike", 20));
        Hs.add(new Person("Leo", 19));
        Hs.add(new Person("Jordan", 21));
        Hs.add(new Person("Jordan", 21));

        for(Person i : Hs){
            System.out.println(i);
        }
    }
}

class Person {
    private String name;
    private int age;

    public Person() {}

    public Person(String name, int age) {
        super();
        this.name = name;
        this.age = age;
    }

    @Override
    public String toString() {
        return "Person{" +
                "name='" + name + '\'' +
                ", age=" + age +
                '}';
    }

    @Override
    public boolean equals(Object o) {
        if (this == o) {
            return true;
        }
        if (o == null || getClass() != o.getClass()) {
            return false;
        }
        Person person = (Person) o;
        return Objects.equals(name, person.name);
    }

    @Override
    public int hashCode() {
        return Objects.hash(name);
    }

}